import React, { Component } from 'react';
import { Dimensions, View, Image,Text,ActionSheetIOS,CameraRoll } from 'react-native';
import Toast from 'react-native-root-toast';
import Icon from 'react-native-vector-icons/Ionicons';
import {UserData} from '../Global';

const SCREEN_WIDTH = Dimensions.get('window').width;

export default class DisplayAnImage extends Component {

    static navigationOptions = ({ navigation }) =>{
        return {
            title: '我的二维码',
            headerRight:(
                <Icon name="ios-more" size={26} color='#000' style={{marginRight:10}}
                onPress={()=>navigation.state.params.showActionSheet()}
                />
            ),
        }

    };
    componentDidMount() {
        this.props.navigation.setParams({showActionSheet:this.showActionSheet})
    }
    showActionSheet = ()=>{
        ActionSheetIOS.showActionSheetWithOptions({
            options: ['保存图片', '取消'],
            cancelButtonIndex: 1,
            tintColor:'#000',
          },
          (buttonIndex) => {
            if (buttonIndex === 0) {
                CameraRoll.saveToCameraRoll(UserData.qrcode,'photo').then(
                    ()=>Toast.show('已保存')
                ).catch(
                    ()=>Toast.show('保存失败')
                );
                
            }
          });
    }
    render() {
        return (
        <View style={{
            flex:1,
            justifyContent: 'center',
            alignItems: 'center',
        }}>
            <View style={{backgroundColor:'#fff',alignItems: 'center',}}>
            <Image
            style={{width: SCREEN_WIDTH-20, height: SCREEN_WIDTH-20}}
            source={{uri: UserData.qrcode}}
            />
            <Text style={{marginVertical:20}}>扫一扫上面的二维码图案，加我美V</Text>
            </View>
        </View>
        );
  }
}